#include "GSBattleMode.h"
#include "GSVictory.h"
#include "GSDefeat.h"

GSBattleMode::GSBattleMode()
{
	SetStateName("GSBATTLEMODE");
}

GSBattleMode::~GSBattleMode()
{

}

void GSBattleMode::OnEnter()
{

	sprBattleBG = Game::GetDevice()->GetDriver()->getTexture("data/sprites/spr_battle.png");
	sprFightScene = Game::GetDevice()->GetDriver()->getTexture("data/sprites/spr_fightscene.png");
	fontCustomBig = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/Showcard_Gothic.png");
	fontCustom = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/fontcourier.bmp");
	fontCustomBig2 = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/bigfont.png");
	fontCustom2 = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/mv_boli.png");
	PLAYER->playerSpr = Game::GetDevice()->GetDriver()->getTexture("data/sprites/youmu.png");
	AIPLAYER->playerSpr = Game::GetDevice()->GetDriver()->getTexture("data/sprites/remilia.png");

	Game::GetDevice()->GetDriver()->makeColorKeyTexture(PLAYER->playerSpr, video::SColor(255,55,55,55));
	Game::GetDevice()->GetDriver()->makeColorKeyTexture(AIPLAYER->playerSpr, video::SColor(255,55,55,55));
	Game::GetDevice()->GetDriver()->makeColorKeyTexture(sprBattleBG, video::SColor(255,55,55,55));
	arrowUp = core::rect<s32>(FACE_ARROW_UP_X, FACE_ARROW_UP_Y, FACE_ARROW_UP_X+FACE_ARROW_WIDTH, FACE_ARROW_UP_Y+FACE_ARROW_HEIGHT);
	arrowDown = core::rect<s32>(FACE_ARROW_DOWN_X, FACE_ARROW_DOWN_Y, FACE_ARROW_DOWN_X+FACE_ARROW_WIDTH, FACE_ARROW_DOWN_Y+FACE_ARROW_HEIGHT);
	arrowLeft = core::rect<s32>(FACE_ARROW_LEFT_X, FACE_ARROW_LEFT_Y, FACE_ARROW_LEFT_X+FACE_ARROW_WIDTH, FACE_ARROW_LEFT_Y+FACE_ARROW_HEIGHT);
	arrowRight = core::rect<s32>(FACE_ARROW_RIGHT_X, FACE_ARROW_RIGHT_Y, FACE_ARROW_RIGHT_X+FACE_ARROW_WIDTH, FACE_ARROW_RIGHT_Y+FACE_ARROW_HEIGHT);
	arrowHolder = arrowLeft;
	
	curkey = (EKEY_CODE)NULL;
	isButtonDown = false;
	
	PLAYER->curX = 0;
	PLAYER->curY = 0;
	PLAYER->face = FACE_RIGHT;

	AIPLAYER->curX = STAGE_COL - 1;
	AIPLAYER->curY = STAGE_ROW - 1;
	AIPLAYER->face = FACE_LEFT;

	PLAYER->isPlayer1=true;
	AIPLAYER->isPlayer1=false;

	ResetPlayer(PLAYER);
	ResetPlayer(AIPLAYER);

	m_bvView.x = CENTER_X;
	m_bvView.y = CENTER_Y;

	//Clear Stage
	for(int i = 0; i < STAGE_ROW; i++)
		for(int j = 0; j < STAGE_COL; j++)
			stage[i][j] = 0;

	WorldReposition(PLAYER);
	WorldReposition(AIPLAYER);
}

void GSBattleMode::OnExit()
{
	Game::GetDevice()->GetDriver()->removeTexture(sprBattleBG);
	Game::GetDevice()->GetDriver()->removeTexture(sprFightScene);
}

void GSBattleMode::Update()
{
	RefreshStage();
	stage[PLAYER->curY][PLAYER->curX] = STAGE_PLAYER;
	stage[AIPLAYER->curY][AIPLAYER->curX] = STAGE_PLAYER;
	gameTime = DEVICE->GetInstance()->getTimer()->getTime();
	//AI Update
	AI_Update(AI_PLAY, PLAYER);
	RegenMove(PLAYER);
	RegenAttack(PLAYER);
	if(DEVICE->receiver.IsKeyDown(KEY_KEY_W) && !isButtonDown)
	{
		curkey = KEY_KEY_W;
		isButtonDown = true;
		Move(PLAYER,AIPLAYER,MOVE_UP);
	}
	else if(DEVICE->receiver.IsKeyDown(KEY_KEY_S) && !isButtonDown)
	{
		curkey = KEY_KEY_S;
		isButtonDown = true;
		Move(PLAYER,AIPLAYER,MOVE_DOWN);
	}
	else if(DEVICE->receiver.IsKeyDown(KEY_KEY_A) && !isButtonDown)
	{
		curkey = KEY_KEY_A;
		isButtonDown = true;
		Move(PLAYER,AIPLAYER,MOVE_LEFT);
	}
	else if(DEVICE->receiver.IsKeyDown(KEY_KEY_D) && !isButtonDown)
	{
		curkey = KEY_KEY_D;
		isButtonDown = true;
		Move(PLAYER,AIPLAYER,MOVE_RIGHT);
	}
	if(DEVICE->receiver.IsKeyDown(KEY_KEY_U))
		PLAYER->face = FACE_UP;
	else if(DEVICE->receiver.IsKeyDown(KEY_KEY_J))
		PLAYER->face = FACE_DOWN;
	else if(DEVICE->receiver.IsKeyDown(KEY_KEY_H))
		PLAYER->face = FACE_LEFT;
	else if(DEVICE->receiver.IsKeyDown(KEY_KEY_K))
		PLAYER->face = FACE_RIGHT;
	if(DEVICE->receiver.IsKeyDown(KEY_KEY_Y) && !isButtonDown)
	{
		curkey = KEY_KEY_Y;
		isButtonDown = true;
		Move(PLAYER,AIPLAYER, MOVE_ATTACK);
	}
	if(DEVICE->receiver.IsKeyUp(KEY_KEY_P))
	{
		PLAYER->cur_move = PLAYER->max_move;
		PLAYER->HealHP(PLAYER->GetMaxHP());
	}
	if(PLAYER->status == STATUS_HIT)
		RefreshPlayerHit(PLAYER);
	RefreshPlayerActions(PLAYER);
	PlayerStatus(PLAYER);

	//quick change of state
	if(CheckKO(AIPLAYER))
	{
		PLAYER->PlayerWin();
		Game::SetState((GameState*)new GSVictory());
	}
	if(CheckKO(PLAYER))
	{
		PLAYER->PlayerLose();
		Game::SetState((GameState*)new GSDefeat());
	}
	if(PLAYER->status == STATUS_MOVE)
	{
		DEBUG_LOG("ratio: %f\nX:%d\nY:%d\n", PLAYER->ratio,m_bvView.x,m_bvView.y);
		m_bvView.x = core::lerp<int>(m_bvView.x, CENTER_X - PLAYER->curX * BOX_SIZE, PLAYER->ratio);
		m_bvView.y = core::lerp<int>(m_bvView.y, CENTER_Y - PLAYER->curY * BOX_SIZE, PLAYER->ratio);
	}
	WorldReposition(PLAYER);
	WorldReposition(AIPLAYER);
	KeyUp(curkey);
}

void GSBattleMode::Render()
{
	Game::GetDevice()->GetDriver()->beginScene(true, true, video::SColor(255,255,255,255));
	//Render Stage
	int start_x = ((SCREEN_WIDTH/2) - (BOX_SIZE * STAGE_COL)/2) + m_bvView.x;
	int start_y = ((SCREEN_HEIGHT/2) - (BOX_SIZE * STAGE_ROW)/2) + m_bvView.y;
	for(int i = 0; i < STAGE_ROW; i++)
	{
		int bY = start_y + i * BOX_SIZE;
		for(int j = 0; j < STAGE_COL; j++)
		{
			int bX = start_x + j * BOX_SIZE;
			Game::GetDevice()->GetDriver()->draw2DRectangleOutline(core::rect<s32>(bX, bY, bX + BOX_SIZE, bY + BOX_SIZE), video::SColor(255,0,0,0));
			if(stage[i][j] == STAGE_OCCUPIED)
				DEVICE->GetDriver()->draw2DRectangle(video::SColor(255,0,0,0),core::rect<s32>(bX, bY, bX + BOX_SIZE, bY + BOX_SIZE));
		}
	}
	RenderPlayerThings(AIPLAYER);
	RenderPlayerThings(PLAYER);
	Game::GetDevice()->GetDriver()->endScene();
}

void GSBattleMode::Attack(Player* pAttack, Player* pReceive)
{
	int min_dmg =  pAttack->GetAtk() - RANGE_DAMAGE_VALUE;
	int max_dmg =  pAttack->GetAtk() + RANGE_DAMAGE_VALUE;
	int range_dmg = max_dmg - min_dmg;
	int atk = rand() % range_dmg + min_dmg;

	pReceive->DamageTaken(atk);
	pReceive->status = STATUS_HIT;
	DEBUG_LOG("PlayerAtk: %s | PlayerRec: %s | ATTACK GENERATED: %d\n", pAttack->GetPlayerName().c_str(), pReceive->GetPlayerName().c_str(), atk);
}

void GSBattleMode::Reset()
{
	Game::GetInstance()->Reset();
}

bool GSBattleMode::CheckCollision(Player* pA, EMOVE move)
{
	switch(move)
	{
	case MOVE_ATTACK: //Attack or Skill
		{
			switch(pA->face)
			{
			case FACE_UP:
				{
					if(stage[pA->curY-1][pA->curX] == STAGE_PLAYER)
						return true;
					break;
				}
			case FACE_DOWN:
				{
					if(stage[pA->curY+1][pA->curX] == STAGE_PLAYER)
						return true;
					break;
				}
			case FACE_LEFT:
				{
					if(stage[pA->curY][pA->curX-1] == STAGE_PLAYER)
						return true;
					break;
				}
			case FACE_RIGHT:
				{
					if(stage[pA->curY][pA->curX+1] == STAGE_PLAYER)
						return true;
					break;
				}
			}
			break;
		}
	case MOVE_UP:
		{
			if(pA->curY-1 >= NULL && stage[pA->curY-1][pA->curX] == STAGE_FREE)
				return true;
			break;
		}
	case MOVE_DOWN:
		{
			if(pA->curY+1 < STAGE_ROW && stage[pA->curY+1][pA->curX] == STAGE_FREE)
				return true;
			break;
		};
	case MOVE_LEFT:
		{
			if(pA->curX-1 >= NULL && stage[pA->curY][pA->curX-1] == STAGE_FREE)
				return true;
			break;
		};
	case MOVE_RIGHT:
		{
			if(pA->curX+1 < STAGE_COL && stage[pA->curY][pA->curX+1] == STAGE_FREE)
				return true;
			break;
		}
	}
	return false;
}

void GSBattleMode::Move(Player* pA,Player* eA, EMOVE move)
{
	bool canAtk = false;
	if(move == MOVE_ATTACK)
	{
		if(pA->cur_attack > NULL && pA->canAct)
		{
			canAtk = true;
			pA->status = STATUS_ATTACK;
			pA->attackTime = gameTime;
			pA->cur_attack--;
		}
	}
	if(CheckCollision(pA, move))
	{
		if(move == MOVE_ATTACK)
		{
			if(canAtk)
				Attack(pA,eA);
		}
		else
		{
			if(pA->cur_move > NULL && pA->canAct)
			{
				pA->status = STATUS_MOVE;
				pA->moveTime = gameTime;
				pA->cur_move--;
				switch(move)
				{
				case MOVE_UP:
					{
						pA->curY--;
						break;
					}
				case MOVE_DOWN:
					{
						pA->curY++;
						break;
					}
				case MOVE_LEFT:
					{
						pA->curX--;
						break;
					}
				case MOVE_RIGHT:
					{
						pA->curX++;
						break;
					}
				}
			}
		}
	}
	pA->canAct = false;
}

void GSBattleMode::KeyUp(EKEY_CODE keyCode)
{
	if(DEVICE->receiver.IsKeyUp(keyCode))
		isButtonDown = false;
}

void GSBattleMode::PlayerStatus(Player* pA)
{
	switch(pA->status)
	{
	case STATUS_IDLE:
		{	
			pA->canAct = true;
			pA->isHit = false;
			IdlePosition(pA);
			pA->bPlay = pA->bIdle;
			break;
		}
	case STATUS_MOVE:
		{
			MovePlayerAnim(pA);
			pA->bPlay = pA->bMove;
			break;
		}
	case STATUS_ATTACK:
		{
			IdlePosition(pA);
			pA->bPlay = pA->bAttack;
			break;
		}
	case STATUS_HIT:
		{
			if(!pA->isHit)
				pA->isHit = true;
			pA->bPlay = pA->bHit;
			break;
		}
	case STATUS_SKILL:
		{
			pA->bPlay = pA->bSkill;
			break;
		}

	}
}

void GSBattleMode::RefreshStage()
{
	for(int i = 0; i < STAGE_ROW; i++)
		for(int j = 0; j < STAGE_COL; j++)
			stage[i][j] = STAGE_FREE;

	//Obstacles
	stage[1][1] = STAGE_OCCUPIED;
	stage[1][3] = STAGE_OCCUPIED;
	stage[2][3] = STAGE_OCCUPIED;
	stage[3][6] = STAGE_OCCUPIED;
}

void GSBattleMode::AI_Update(AIPlayer* aiAp, Player* pA)
{
	//All AI related things here
	RegenMove(aiAp->GetInstance());
	RegenAttack(aiAp->GetInstance());
	if(aiAp->GetInstance()->canAct)
		Move(aiAp->GetInstance(), pA, aiAp->GenerateMove(pA)); 
	RefreshPlayerActions(aiAp->GetInstance());
	if(aiAp->GetInstance()->status == STATUS_HIT)
		RefreshPlayerHit(aiAp->GetInstance());
	PlayerStatus(aiAp->GetInstance());
}

void GSBattleMode::RefreshPlayerActions(Player* pA)
{
	if(!pA->canAct)
	{
		if(pA->attackTime != NULL && gameTime - pA->attackTime >= pA->atkcooldown)
		{
			pA->status = STATUS_IDLE;
			pA->attackTime = NULL;
			pA->moveTime = NULL;
		}
		if(pA->moveTime != NULL && gameTime - pA->moveTime >= pA->movcooldown)
		{
			pA->status = STATUS_IDLE;
			pA->attackTime = NULL;
			pA->moveTime = NULL;
		}
	}
}

void GSBattleMode::RefreshPlayerHit(Player* pA)
{
	if(pA->status == STATUS_HIT && pA->hitTime == NULL)
	{
		pA->canAct = false;
		pA->hitTime = gameTime;
	}
	if(pA->hitTime != NULL && gameTime - pA->hitTime >= pA->hitcooldown)
	{
		pA->canAct = true;
		pA->status = STATUS_IDLE;
		pA->hitTime = NULL;
	}
}

void GSBattleMode::RegenMove(Player* pA)
{
	if(pA->cur_move < pA->max_move && !pA->m_isMovregen)
	{
		pA->movregtime = gameTime;
		pA->m_isMovregen = true;
	}
	if(pA->m_isMovregen)
	{
		if(gameTime - pA->movregtime >= pA->movTimeLapse)
		{
			pA->cur_move++;
			pA->m_isMovregen = false;
		}
	}
}

void GSBattleMode::RegenAttack(Player* pA)
{
	if(pA->cur_attack < pA->max_attack && !pA->m_isAtkregen)
	{
		pA->atkregtime = gameTime;
		pA->m_isAtkregen = true;
	}
	if(pA->m_isAtkregen)
	{
		if(gameTime - pA->atkregtime >= pA->atkTimeLapse)
		{
			pA->cur_attack++;
			pA->m_isAtkregen = false;
		}
	}
}

bool GSBattleMode::CheckKO(Player* pA)
{
	if(pA->GetHealthPoint() <= 0)
	{
		return true;
	}
	return false;
}

void GSBattleMode::ResetPlayer(Player* pA)
{
	pA->cur_move = pA->max_move;
	pA->cur_attack = pA->max_attack;
	pA->canAct - true;
	pA->status = STATUS_IDLE;
	int start_x = ((SCREEN_WIDTH/2) - (BOX_SIZE * STAGE_COL)/2) + m_bvView.x;
	int start_y = ((SCREEN_HEIGHT/2) - (BOX_SIZE * STAGE_ROW)/2) + m_bvView.y;
	int xOffset = 5;
	int yOffset = 10;
	pA->sprX = (start_x + BOX_SIZE * pA->curX) + xOffset;
	pA->sprY = (start_y + BOX_SIZE * pA->curY) + yOffset;
	pA->position.UpperLeftCorner.X = pA->sprX;
	pA->position.UpperLeftCorner.Y = pA->sprY;
	pA->position.LowerRightCorner.X = pA->sprX+ pA->bPlay.getWidth();
	pA->position.LowerRightCorner.X = pA->sprY + pA->bPlay.getHeight();
}

void GSBattleMode::RenderPlayerThings(Player* pA)
{
	Game::GetDevice()->GetDriver()->draw2DImage(pA->playerSpr, pA->position, pA->bPlay,0,0,true);

	s_PlayerHP = "";
	s_PlayerHP += pA->GetHealthPoint();
	s_PlayerHP += "/";
	s_PlayerHP += pA->GetMaxHP();
	s_PlayerMP = "";
	s_PlayerMP += pA->GetManaPoint();
	s_PlayerMP += "/";
	s_PlayerMP += pA->GetMaxMP();


	s_Move = "";
	s_Move += pA->cur_move;
	s_Move += "/";
	s_Move += pA->max_move;
	s_Attack = "";
	s_Attack += pA->cur_attack;
	s_Attack += "/";
	s_Attack += pA->max_attack;

	float h1,h2,m1,m2;
	h1 = pA->GetHealthPoint();
	h2 = pA->GetMaxHP();
	m1 = pA->GetManaPoint();
	m2 = pA->GetMaxMP();

	int arrow_x = 0;
	int arrow_y = 0;
	
	switch(pA->face)
	{
	case FACE_UP:
		{
			arrow_x = pA->sprX + pA->bIdle.getWidth()/2 - arrowHolder.getWidth()/2;
			arrow_y = pA->sprY - arrowHolder.getHeight() + 2;
			arrowHolder = arrowUp;
			break;
		}
	case FACE_DOWN:
		{
			arrow_x = pA->sprX + pA->bIdle.getWidth()/2 - arrowHolder.getWidth()/2;
			arrow_y = pA->sprY+pA->bIdle.getHeight() + 2;
			arrowHolder = arrowDown;
			break;
		}
	case FACE_LEFT:
		{
			arrow_y = pA->sprY + pA->bIdle.getHeight()/2 - arrowHolder.getHeight()/2;
			arrow_x = pA->sprX - arrowHolder.getWidth() + 2;
			arrowHolder = arrowLeft;
			break;
		}
	case FACE_RIGHT:
		{
			arrow_y = pA->sprY + pA->bIdle.getHeight()/2 - arrowHolder.getHeight()/2;
			arrow_x = pA->sprX + pA->bIdle.getWidth() + 2;
			arrowHolder = arrowRight;
		}
	}


	if(pA->isPlayer1)
	{
		//Draw Player Name
		fontCustomBig2->draw(pA->GetPlayerName(), core::rect<s32>(PLAYER_NAME_LOCATION_X, PLAYER_NAME_LOCATION_Y, 40, 10), video::SColor(255,255,255,255));
		//HP & MP
		DEVICE->GetDriver()->draw2DRectangle((h1/h2)*100 > 25?video::SColor(255,0,255,0):video::SColor(255,255,0,0),core::rect<s32>(HP_BOX_X_P1+(HP_RECT_W*(h2-h1)/h2),HP_BOX_Y_P1, HP_BOX_X_P1+HP_RECT_W, HP_BOX_Y_P1+HP_RECT_H));
		DEVICE->GetDriver()->draw2DRectangle(video::SColor(255,0,0,255),core::rect<s32>(MP_BOX_X_P1,MP_BOX_Y_P1, MP_BOX_X_P1+ MP_RECT_W, MP_BOX_Y_P1+MP_RECT_H));
		DEVICE->GetDriver()->draw2DRectangleOutline(core::rect<s32>(HP_BOX_X_P1,HP_BOX_Y_P1, HP_BOX_X_P1+HP_RECT_W, HP_BOX_Y_P1+HP_RECT_H),video::SColor(255,0,0,0));
		DEVICE->GetDriver()->draw2DRectangleOutline(core::rect<s32>(MP_BOX_X_P1,MP_BOX_Y_P1, MP_BOX_X_P1+MP_RECT_W, MP_BOX_Y_P1+MP_RECT_H),video::SColor(255,0,0,0));

		//MOVE & ATTACK
		fontCustomBig->draw("Move", core::rect<s32>(MOVE_S_X_P1, MOVE_S_Y_P1 - 30, 40,10),video::SColor(255,0,0,0));
		fontCustomBig->draw("Attack", core::rect<s32>(ATTACK_S_X_P1, ATTACK_S_Y_P1 - 30, 40,10),video::SColor(255,0,0,0));
		fontCustom2->draw(s_Move, core::rect<s32>(MOVE_S_X_P1, MOVE_S_Y_P1, 70, 10), video::SColor(255,0,0,0));
		fontCustom2->draw(s_Attack, core::rect<s32>(ATTACK_S_X_P1, ATTACK_S_Y_P1, 70, 10), video::SColor(255,0,0,0));

	}
	else
	{
		fontCustomBig2->draw(pA->GetPlayerName(), core::rect<s32>(ENEMY_NAME_LOCATION_X, ENEMY_NAME_LOCATION_Y, 40, 10), video::SColor(255,255,255,255));
		DEVICE->GetDriver()->draw2DRectangle((h1/h2)*100 > 25?video::SColor(255,0,255,0):video::SColor(255,255,0,0),core::rect<s32>(HP_BOX_X_P2,HP_BOX_Y_P2, HP_BOX_X_P2+HP_RECT_W*(h1/h2), HP_BOX_Y_P2+HP_RECT_H));
		DEVICE->GetDriver()->draw2DRectangle(video::SColor(255,0,0,255),core::rect<s32>(MP_BOX_X_P2,MP_BOX_Y_P2, MP_BOX_X_P2+MP_RECT_W, MP_BOX_Y_P2+MP_RECT_H));
		DEVICE->GetDriver()->draw2DRectangleOutline(core::rect<s32>(HP_BOX_X_P2,HP_BOX_Y_P2, HP_BOX_X_P2+HP_RECT_W, HP_BOX_Y_P2+HP_RECT_H),video::SColor(255,0,0,0));
		DEVICE->GetDriver()->draw2DRectangleOutline(core::rect<s32>(MP_BOX_X_P2,MP_BOX_Y_P2, MP_BOX_X_P2+MP_RECT_W, MP_BOX_Y_P2+MP_RECT_H),video::SColor(255,0,0,0));

		fontCustomBig->draw("Move", core::rect<s32>(MOVE_S_X_P2-70, MOVE_S_Y_P2 - 30, 40,10),video::SColor(255,0,0,0));
		fontCustomBig->draw("Attack", core::rect<s32>(ATTACK_S_X_P2-70, ATTACK_S_Y_P2 - 30, 40,10),video::SColor(255,0,0,0));
		fontCustom2->draw(s_Move, core::rect<s32>(MOVE_S_X_P2 - 70, MOVE_S_Y_P2, 70, 10), video::SColor(255,0,0,0));
		fontCustom2->draw(s_Attack, core::rect<s32>(ATTACK_S_X_P2-70, ATTACK_S_Y_P2, 70, 10), video::SColor(255,0,0,0));
	}
	DEVICE->GetDriver()->draw2DImage(sprBattleBG, core::rect<s32>(arrow_x, arrow_y, arrow_x+FACE_ARROW_WIDTH, arrow_y+FACE_ARROW_HEIGHT), arrowHolder, 0, 0, true);
	fontCustom->draw(s_PlayerHP, pA->isPlayer1? core::rect<s32>((HP_BOX_X_P1+HP_RECT_W)/2, HP_BOX_Y_P1+2,70,10):core::rect<s32>(HP_BOX_X_P2+(HP_RECT_W/2), HP_BOX_Y_P2+2,70,10), video::SColor(255,0,0,0));
	fontCustom->draw(s_PlayerMP, pA->isPlayer1? core::rect<s32>((MP_BOX_X_P1+HP_RECT_W)/2, MP_BOX_Y_P1+2,70,10):core::rect<s32>(MP_BOX_X_P2+(MP_RECT_W/2), MP_BOX_Y_P2+2,70,10), video::SColor(255,255,255,255));
}

void GSBattleMode::WorldReposition(Player* pA)
{
	pA->position.UpperLeftCorner.X = pA->sprX;
	pA->position.UpperLeftCorner.Y = pA->sprY;
	pA->position.LowerRightCorner.X = pA->sprX+ pA->bPlay.getWidth();
	pA->position.LowerRightCorner.Y = pA->sprY + pA->bPlay.getHeight();
}

void GSBattleMode::MovePlayerAnim(Player* pA)
{
	int start_x = ((SCREEN_WIDTH/2) - (BOX_SIZE * STAGE_COL)/2)  + m_bvView.x;
	int start_y = ((SCREEN_HEIGHT/2) - (BOX_SIZE * STAGE_ROW)/2)  + m_bvView.y;
	int xOffset = 5;
	int yOffset = 10;
	pA->ratio = (double)(gameTime - pA->moveTime)/(double)pA->movcooldown;
	pA->sprX = core::lerp<int>(pA->sprX,(start_x + BOX_SIZE * pA->curX) + xOffset, pA->ratio);
	pA->sprY = core::lerp<int>(pA->sprY,(start_y + BOX_SIZE * pA->curY) + yOffset, pA->ratio);
}

void GSBattleMode::IdlePosition(Player* pA)
{
	pA->ratio = 0;
	int start_x = ((SCREEN_WIDTH/2) - (BOX_SIZE * STAGE_COL)/2)  + m_bvView.x;
	int start_y = ((SCREEN_HEIGHT/2) - (BOX_SIZE * STAGE_ROW)/2)  + m_bvView.y;
	int xOffset = 5;
	int yOffset = 10;
	pA->sprX = start_x + BOX_SIZE * pA->curX + xOffset;
	pA->sprY = start_y + BOX_SIZE * pA->curY + yOffset;
}